<!--
 * @Author: your name
 * @Date: 2021-03-15 11:20:25
 * @LastEditTime: 2021-03-17 16:07:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\warranty\warrantyStatistics\reject.vue
-->
<template>
    <div class="reject-mian-box">
        <el-dialog
        :title="$t('warranty.reject')"
        :visible="rightVisible"
        width="1050px"
        @close="()=>{$store.commit('setRightVisible',false)}"
        :close-on-click-modal='false'
        >  
            <div class='reject-modal-mian-box'>
                <div class="add-reject-msg-box">
                    <span>{{$t('warranty.reject.reason')}}： </span>
                    <el-input v-model="reason" style="width:360px;margin:0 15px;"></el-input>
                    <el-button type="primary" @click='crmnoticeSave' :disabled="checkListGroup.length>10 || checkListGroup.length==10?true:false">{{$t('add')}}</el-button>
                    <el-button type="" @click='crmnoticeDeleteBatch'>{{$t('delete')}}</el-button>
                </div>
                <div class="reject-list-msg-box">
                    <el-checkbox-group v-model="checkList">
                        <el-checkbox :label="item.notice" v-for='item in checkListGroup' :key='item.sid'></el-checkbox>
                    </el-checkbox-group>
                </div>
                <div class="reject-list-msg-content">
                    <div class="header-box">
                        {{$t('warranty.reject.email.content')}}
                    </div>
                    <div class="texteare-box">
                        Dear customer,
                        <br>
                        <br>
 
    &nbsp;&nbsp;&nbsp;&nbsp;The following information(<span style='display:inline-block;background-color:rgb(240, 176, 0);'>{{checkList.join(',')}}</span>)of warranty registration you filled in is wrong, please go to this link below to modify the information. We will approve your warranty registration as soon as possible after you modify it correctly.<br><br>

    https://www.solaxcloud.com/……<br><br>
    
    Thanks！<br>
    SolaX Power<br>
    -------------------------------<br>
    This is an automatically generated email. Please don't reply to this email.<br>
    If you have any question,please contact our service:service@solaxpower.com.
                    </div>
                </div>
                
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setRightVisible',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="qualityNewRejectQuality">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {

    },
    data() {
        return {
            reason:'',
            checkList:[],
            checkListGroup:[],
            emailContent:`Dear customer,
 
    The following information(4444,5555,6666)of warranty registration you filled in is wrong, please go to this link below to modify the information. We will approve your warranty registration as soon as possible after you modify it correctly.

    https://www.solaxcloud.com/……
    
    Thanks！
    SolaX Power
    -------------------------------
    This is an automatically generated email. Please don't reply to this email.
    If you have any question,please contact our service:service@solaxpower.com.`,

        };
    },
    computed: {
        rightVisible(){
            return this.$store.state.sysStore.rightVisible
        },
        rejectWarrantyId(){
            return this.$store.state.sysStore.rejectWarrantyId
        },
    },
    watch: {

    },
    created() {

    },
    mounted() {
        this.crmnoticeGetList()
    },
    methods: {
        async qualityNewRejectQuality(){
            if(this.checkList.length == 0){
                this.comm.showMsg(false,this.$t('warranty.reject.notices'))
                return 
            }
            let res = await this.API.qualityNewRejectQuality({
                ids:this.rejectWarrantyId,
                notices:this.checkList,
            })
            if(this.comm.showMsg(res.success)){
                this.$store.commit('setVisibleAdd2',false)
                this.$store.commit('setRightVisible',false)
                this.checkList = []
                this.$emit('uploadData',true)
            }
        },
        async crmnoticeDeleteBatch(){
            let ids  = []
            this.checkList.forEach(item =>{
                this.checkListGroup.forEach(items =>{
                    if(item == items.notice){
                        ids.push(items.sid)
                    }
                })
            })
            let res = await this.API.crmnoticeDeleteBatch({
                ids
            })
            if(this.comm.showMsg(res.success)){
                this.crmnoticeGetList()
            }
        },
        async crmnoticeSave(){
            let res = await this.API.crmnoticeSave({
                notices:this.reason
            })
            if(this.comm.showMsg(res.success)){
                this.crmnoticeGetList()
                this.reason = ''
            }
        },
        async crmnoticeGetList(){
            let res = await this.API.crmnoticeGetList({})
            this.checkListGroup = res
        }
    },
};
</script>

<style  lang="less" scoped>
.reject-modal-mian-box{
    padding: 0 40px;
    .add-reject-msg-box{
        display: flex;
        align-items: center;
    }
    .reject-list-msg-box{
        padding: 15px 0;
    }
    .reject-list-msg-content{
        .header-box{
            font-size: 20px;
            font-weight: 700;
            padding: 10px 0px;
        }
    }
    .texteare-box{
        border:1px solid rgb(240, 176, 0);
        padding: 10px;
    }
}
</style>
